package com.lanou.myapp.funny.videofunny;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.lanou.myapp.R;
import com.lanou.myapp.imageloader.GsonRequest;
import com.lanou.myapp.imageloader.VolleySingleton;

/**
 * Created by dllo on 16/1/25.
 */
public class VideoFragment extends Fragment{
    private Context context;
    private RecyclerView recyclerView;
    private VideoFunnyAdapter adapter;
    private String url = "http://s.budejie.com/topic/list/jingxuan/41/budejie-android-6.3.0/0-20.json?market=tencentyingyongbao&ver=6.3.0&visiting=&os=5.1&appname=baisibudejie&client=android&udid=000000000000000&mac=08%3A00%3A27%3A3f%3A7a%3A01";


    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.context = context;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        recyclerView = (RecyclerView) getActivity().findViewById(R.id.recyclerView_video_funny);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        adapter = new VideoFunnyAdapter(getActivity());

        GsonRequest<VideoFunnyBeans> request = new GsonRequest<VideoFunnyBeans>(url, VideoFunnyBeans.class, new Response.Listener<VideoFunnyBeans>() {
            @Override
            public void onResponse(VideoFunnyBeans response) {
                adapter.addData(response.getList());
                recyclerView.setAdapter(adapter);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });
        VolleySingleton.getInstance()._addRequest(request);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = LayoutInflater.from(context).inflate(R.layout.video_funny_fragment,null);
        return view;
    }




}
